package com.kfm.am;

import java.util.*;

public class Test05 {

    public static void main(String[] args) {

        String classes = "abbccdd";
        // String key 是字符串的每一个字符 value 是字符出现的次数
        HashMap<String, Integer> classHashMap = new HashMap<>();
        for (int i = 0; i < classes.length(); i ++) {
            char c = classes.charAt(i);
            if (classHashMap.containsKey(c + "")) { // classHashMap 里面存在 c 对应的映射
                Integer value = classHashMap.get(c + "");
                classHashMap.put(c + "", value + 1);
            } else {
                classHashMap.put(c + "", 1);
            }
        }
        int max = 0;
        String str = "";
        Set<Map.Entry<String, Integer>> entrySet = classHashMap.entrySet();
        for (Map.Entry<String, Integer> e : entrySet) {
            if (max < e.getValue()) {
                max = e.getValue();
                str = e.getKey();
            }
        }
        System.out.println("最想去的景点是：" + str);
        System.out.println(classHashMap);

    }
}
